package team.pwy.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import team.pwy.consts.RbmConsts;

import java.util.HashMap;
import java.util.Map;

/**
 * 本来用来演示:
 *
 * @author feng
 * @date 2023/10/18
 * @Description
 */
@Configuration
public class RbmConfig {
    // 创建收藏队列
    @Bean
    public Queue queue01(){
        return new Queue(RbmConsts.SEC_QUEUE_COLLECT);
    }
    // 创建评分队列
    @Bean
    public Queue queueScore(){
    return new Queue(RbmConsts.SCORE_QUEUE);
}
    @Bean
    public Queue queue02(){
        return new Queue(RbmConsts.PHO_QUEUE);
    }

    /**
     * @return Queue
     * @author DaiLing
     * @description 注册支付成功简单队列
     * @date 2024/1/24 16:12
     */
    @Bean
    public Queue orderSuccess() {
        return new Queue(RbmConsts.ORDER_SUCCESS);
    }

    /**
     * @return Queue
     * @author DaiLing
     * @description 注册支付失败正常队列
     * @date 2024/1/24 16:12
     */
    @Bean
    public Queue orderError() {
        Map<String, Object> args = new HashMap<>();
        // 设置队列的死信交换机
        args.put("x-dead-letter-exchange", RbmConsts.DELAYED_ORDER_EXCHANGE);
        // 设置死信队列
        args.put("x-dead-letter-routing-key", RbmConsts.DELAYED_ORDER_ERROR);
        // 设置消息的过期时间，这里设置为15分钟
        args.put("x-message-ttl", 150 * 1000);

        return new Queue(RbmConsts.ORDER_ERROR, true, false, false, args);
    }

    /**
     * @return Queue
     * @author DaiLing
     * @description 注册支付失败死信队列
     * @date 2024/1/24 16:18
     */
    @Bean
    public Queue delayedOrderError() {
        return new Queue(RbmConsts.DELAYED_ORDER_ERROR);
    }

    /**
     * @return FanoutExchange
     * @author DaiLing
     * @description 注册支付失败死信交换机
     * @date 2024/1/24 16:19
     */
    @Bean
    public FanoutExchange delayedOrderExchange() {
        return new FanoutExchange(RbmConsts.DELAYED_ORDER_EXCHANGE);
    }

    /**
     * @return Binding
     * @author DaiLing
     * @description 将支付失败死信队列绑定到死信交换机
     * @date 2024/1/24 16:21
     */
    @Bean
    public Binding bindDelayedOrderError() {
        return BindingBuilder.bind(delayedOrderError())
                .to(delayedOrderExchange());
    }

    @Bean
    public Queue queueMember(){
        return new Queue(RbmConsts.MEMBER_QUEUE);
    }

    @Bean
    public Queue orderSuccessQueue (){
        return new Queue(RbmConsts.ORDERSUCCESS_QUEUE);
    }

}
